﻿using System;
using System.IO;

namespace ETModel
{
	public static class ConfigHelper
	{
        /// <summary>
        /// 
        /// </summary>
        /// <param name="configFileInfo">配置文件所在目录,相对服务器运行目录</param>
        /// <param name="key"></param>
        /// <returns></returns>
		public static string GetText(string configFileInfo, string key)
		{
            string path = Path.Combine(configFileInfo, $"{key}.txt");
			try
			{
				string configStr = File.ReadAllText(path);
				return configStr;
			}
			catch (Exception e)
			{
				throw new Exception($"load config file fail, path: {path} {e}");
			}
		}

		public static T ToObject<T>(string str)
		{
			return JsonHelper.FromJson<T>(str);
		}
	}
}
